package entities;

import static forplay.core.ForPlay.*;

import forplay.core.GroupLayer;
import forplay.core.Image;
import forplay.core.ImageLayer;
import forplay.core.ResourceCallback;

public class Bullet {
  public static String IMAGE = "images/bullet.png";
  private ImageLayer layer;
  private float angle, x ,y;
  
  public Bullet(final GroupLayer bulletLayer, final float px, final float py)
  {
    x = px;
    y = py;
    angle = 0;
    Image image = assetManager().getImage(IMAGE);
    layer = graphics().createImageLayer(image);
    
    // Add a callback for when the image loads.
    // This is necessary because we can't use the width/height (to center the
    // image) until after the image has been loaded
    image.addCallback(new ResourceCallback<Image>() {
      @Override
      public void done(Image image) {
        layer.setOrigin(image.width() / 2f, image.height() / 2f);
        layer.setTranslation(x, y);
        bulletLayer.add(layer);
      }

      @Override
      public void error(Throwable err) {
        log().error("Error loading image!", err);
      }
    });
  }
 

  public void update(float delta) {
    layer.setTranslation(this.x, this.y--);
  }
}
